package cn.comon.app.report;

import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.comon.app.scan.analysis.IAnalysis;
import cn.comon.app.scan.entity.AsReportinfo;
import cn.comon.app.scan.service.AsReportinfoService;
import cn.comon.app.scan.util.UtilTools;

public class ScanQuartzJob{
    @Autowired
    private AsReportinfoService asReportinfoService;
    static Logger logger = Logger.getLogger(ScanQuartzJob.class.getName());
    /**第三方接口参数读取文件 */
    private static final String FILE_NAME = "Analysis.properties";
    //访问腾讯第三方接口所需参数
    /**腾讯提供的第三方请求地址*/
    private static String QQ_URL = null;
//    @Autowired
//    private IAnalysis tencentAnalysis;
//    @Autowired
//    private IAnalysis netQinAnalysis;
//    @Autowired
//    private IAnalysis dubaAnalysis;
//    @Autowired
//    private IAnalysis aQGJAnalysis;
    @Autowired
    private IAnalysis iAnalysisImpl;
    /**一次发送的最大条数*/
    private static String SELECT_MAX_SIZE = null;
    /**腾讯手机管家提供合作方id*/
    private static String QQ_CHANNEL_ID = null;
    /**腾讯提供的密钥*/
    private static String QQ_SECURE_KEY = null;
    
    private Properties props;
    /**第三方接口参数List*/
    private static HashMap<String, String> PARAM_LIST = new HashMap<String, String>();
    
//    private ThreadPoolExecutor pool = new ThreadPoolExecutor(0, 0, 0, null, null);
    
    //访问金山毒霸第三方接口所需参数
    //访问网秦第三方接口所需参数
    //访问安全管家第三方接口所需参数
    
    public ScanQuartzJob () {
        logger.info("ScanQuartzJob Start");
        logger.info("请求发送初始化");
        props = UtilTools.getPropertiesFile(FILE_NAME);
        //每次发送的最大信息条数
        SELECT_MAX_SIZE = props.getProperty("select.maxsize");
        //第三方检测接口参数
        QQ_URL = props.getProperty("qq.url");
        QQ_CHANNEL_ID = props.getProperty("qq.channelId");
        QQ_SECURE_KEY = props.getProperty("qq.secureKey");
        
        
        PARAM_LIST.put("qq.url", QQ_URL);
        PARAM_LIST.put("qq.channelId", QQ_CHANNEL_ID);
        PARAM_LIST.put("qq.secureKey", QQ_SECURE_KEY);
        //Spring 注入类名
//        ApplicationContext context = null;
//        context.getBean("dsa");
        
        logger.info("qq.url:" + QQ_URL);
        logger.info("qq.channelId:" + QQ_CHANNEL_ID);
        logger.info("qq.secureKey:" + QQ_SECURE_KEY);
        logger.info("请求发送初始化完毕");
        logger.info("ScanQuartzJob End");
    }
    public void startScan(){
        try {
            logger.info("ScanQuartzJob.startScan Start");
            logger.info("向第三方发送检测请求...Start");
            //检索数据表【as_reportinfo】，取得需要检测的数据，每次SELECT_MAX_SIZE条
            List<AsReportinfo> appDataList =
                asReportinfoService.getReportinfoMaxSize(Integer.parseInt(SELECT_MAX_SIZE));
            //iAnalysisImpl.sendRequest(PARAM_LIST, appDataList);
            if (appDataList != null && appDataList.size() > 0) {
                iAnalysisImpl.sendRequest(props, appDataList);
            }
            logger.info("向第三方发送检测请求...end");
        } catch (Exception e) {
            logger.error(e.getMessage());
         }
    }
}